import { ResPage, Warehouse } from "@/api/interface/index";
import { WAREHOUSE, PROCUREDCENTER } from "@/api/config/servicePort";
import http from "@/api";

/**
 * @name 库房管理模块
 */

// 获取出入库单列表
export const getEntryOutList = (params: Warehouse.ReqEntryOutParams) => {
  return http.post<ResPage<Warehouse.ResEntryOutList>>(WAREHOUSE + `/circulationOrder/page`, params);
};

// 出库
export const outbound = (params: { circulationId: number; warehouseId: number }) => {
  return http.post(WAREHOUSE + `/circulationOrder/outbound`, params);
};

// 入库
export const inbound = (params: { circulationId: number; warehouseId: number }) => {
  return http.post(WAREHOUSE + `/circulationOrder/inbound`, params);
};

// 导出出入库单数据
export const exportEntryOutInfo = (params: Warehouse.ReqEntryOutParams) => {
  return http.download(WAREHOUSE + `/entryOut/export`, params);
};

// 获取供应商名称和地址
export const getVendor = (params: { goodsId: number }) => {
  return http.post<{ vendorName: string; vendorAddress: { addressString: string } }>(
    PROCUREDCENTER + `/vendor/getByGoodsId`,
    params
  );
};

// 获取库房名称和地址 0-货物来源库房信息 1-货物目的库房信息
export const getWarehouse = (params: { circulationId: number; resAim: number }) => {
  return http.post<{ warehouseName: string; warehouseAddress: { addressString: string } }>(
    WAREHOUSE + `/circulationOrder/getSourceWarehouseInfo`,
    params
  );
};

// 获取库房信息
export const getWarehouseInfo = (params: { warehouseId: number }) => {
  return http.post<Warehouse.WarehouseInfo>(WAREHOUSE + `/get`, params);
};

// 获取库存信息
export const getInventory = (params: { warehouseId: number }) => {
  return http.post<Warehouse.InventoryData>(WAREHOUSE + `/inventory/page`, params);
};

// 导出库存数据
export const exportInventoryInfo = (params: Warehouse.ReqEntryOutParams) => {
  return http.download(WAREHOUSE + `/inventory/export`, params);
};

// 获取库房列表
export const getWarehouseList = (params: Warehouse.ReqWarehouseParams) => {
  return http.post<ResPage<Warehouse.ResWarehouseList>>(WAREHOUSE + `/page`, params);
};

// 新增库房
export const addWarehouse = (params: any) => {
  return http.post(WAREHOUSE + `/create`, params);
};

// 修改库存信息
export const modifyHold = (params: { inventoryId: number; maxHold: number; warnHold: number }) => {
  return http.post(WAREHOUSE + `/inventory/update`, params);
};

// 补货
export const supplyHold = (params: Warehouse.ResSupply) => {
  return http.post(WAREHOUSE + `/inventory/purchase`, params);
};

// 批量添加库房
export const BatchAddWarehouse = (params: FormData) => {
  return http.post(WAREHOUSE + `/warehouse/import`, params);
};

// 导出库房数据
export const exportWarehouseInfo = (params: Warehouse.ResWarehouseList) => {
  return http.download(WAREHOUSE + `/warehouse/export`, params);
};

// 删除库房
export const deleteWarehouse = (params: { warehouseId: string[] }) => {
  return http.post(WAREHOUSE + `/warehouse/delete`, params);
};

// 获取分站列表（名称）
export const getWarehouseNameList = () => {
  return http.get<Warehouse.ResWarehouseList[]>(WAREHOUSE + `/list`);
};
